$(document).ready(function() {

    queryGoodsList();
    
});

var queryGoodsList = function () {


    var categoryId = getUrlParms("categoryId");


    $.ajax({
        url: "http://localhost:8002/category/queryAllCategory/"+categoryId,
        type: "GET",
        async: true,
        data: null,
        dataType: "json",
        success: function (data) {

            if (data.code===201) {

                var dataLength = data.data.length;

                var rows = Math.ceil(dataLength/2);
                var rows1 = dataLength%2;

                var goods = data.data;

                console.log(goods)

                for (var i = 1;i<=rows;i++){


                    $("#J_channelPage").append(
                        "<div class=\"container channel-product channel-product-two4 J_channelLazyBox\">\n" +

                        "        <div class=\"row\" id=list-"+i+">\n" +


                        "        </div>\n" +
                        "    </div>"+
                        "<div class='container channel-line' style=' height:14px; background-color:#f5f5f5;'></div>"
                    )

                    if (rows===i && rows1===1) {
                        $("#list-"+i).append(
                            "<div class=\"container channel-product channel-product-two4 J_channelLazyBox\">\n" +

                            "        <div class=\"row\" id=list-"+i+">\n" +

                            "            <div class=\"span10 product-cell shadow\">\n" +
                            "                <div class=\"figure\"><a class=\"exposure\" href="+goods[2*i-2].buyUrl+">\n" +
                            "                    <img class=\"J_lazy\"\n" +
                            "                         src="+goods[2*i-2].spuImage+"" +
                            "                         alt="+goods[2*i-2].goodsName+" style=\"background-color:#B8B7C2;\"> </a></div>\n" +
                            "                <h3 class=\"title\"><a class=\"exposure\" href="+goods[2*i-2].buyUrl+">"+goods[2*i-2].goodsName+"</a></h3>\n" +
                            "                <p class=\"desc\">"+goods[2*i-2].spuIntro+"</p>\n" +
                            "                <p class=\"price\"><strong>"+goods[2*i-2].lowPrice+"</strong>元起 </p>\n" +
                            "            </div>\n" +

                            "        </div>\n" +
                            "    </div>"
                        )
                    }else {
                        $("#list-"+i).append(
                            "<div class=\"container channel-product channel-product-two4 J_channelLazyBox\">\n" +

                            "        <div class=\"row\" id=list-"+i+">\n" +

                            "            <div class=\"span10 product-cell shadow\">\n" +
                            "                <div class=\"figure\"><a class=\"exposure\" href="+goods[2*i-2].buyUrl+">\n" +
                            "                    <img class=\"J_lazy\"\n" +
                            "                         src="+goods[2*i-2].spuImage+"" +
                            "                         alt="+goods[2*i-2].goodsName+" style=\"background-color:#B8B7C2;\"> </a></div>\n" +
                            "                <h3 class=\"title\"><a class=\"exposure\" href="+goods[2*i-2].buyUrl+">"+goods[2*i-2].goodsName+"</a></h3>\n" +
                            "                <p class=\"desc\">"+goods[2*i-2].spuIntro+"</p>\n" +
                            "                <p class=\"price\"><strong>"+goods[2*i-2].lowPrice+"</strong>元起 </p>\n" +
                            "            </div>\n" +

                            "            <div class=\"span10 product-cell shadow\">\n" +
                            "                <div class=\"figure\"><a class=\"exposure\" href="+goods[2*i-1].buyUrl+">\n" +
                            "                    <img class=\"J_lazy\"\n" +
                            "                         src="+goods[2*i-1].spuImage+"" +
                            "                         alt="+goods[2*i-1].goodsName+" style=\"background-color:#B8B7C2;\"> </a></div>\n" +
                            "                <h3 class=\"title\"><a class=\"exposure\" href="+goods[2*i-1].buyUrl+">"+goods[2*i-1].goodsName+"</a></h3>\n" +
                            "                <p class=\"desc\">"+goods[2*i-1].spuIntro+"</p>\n" +
                            "                <p class=\"price\"><strong>"+goods[2*i-1].lowPrice+"</strong>元起 </p>\n" +
                            "            </div>\n" +

                            "        </div>\n" +
                            "    </div>"
                        )
                    }
                }

            }else{
                layer.msg("加载失败!");
            }
        },
        error: function () {
            layer.msg("加载失败!");
        }


    })
}
